<template>
	<view>
		<customHeader centerTitle="常购清单" backThem="dark" :back="false">
			<template v-slot:bg>
				<image class="head-bg" src="../../static/image/version/headBg.png"></image>
			</template>
		</customHeader>
		<view class="boxs-row">
			<view v-if="shopList.length">
				<view v-for="(it, ix) in shopList" :key="ix" class="shop-rows" @click="goDetail(it)" hover-class="hover_class">
					<image mode="aspectFill" :src="it.image"></image>
					<view>
						<view>
							<view>购买过</view>
							<text>{{ it.name }}</text>
						</view>
						<view class="des">{{ it.describe }}</view>
						<view class="prices">
							<view>
								<text>￥</text>
								<view>{{it.shopPrice || 0}}</view>
							</view>
							<view @click.stop="addCart(it)" hover-class="hover_class">
								<view v-if="it.cartNum" class="add-car">
									<image src="../../static/image/version/add.png"></image>
									<view>{{it.cartNum}}</view>
								</view>
								<image src="../../static/image/version/car.png" v-else></image>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-else class="empty-car">
				<empty title="暂无数据"/>
			</view>
		</view>
		<rulePop ref="rulePop" />
	</view>
</template>

<script>
import store from '@/store'
import {
	quickList
} from 'utils/api/order'
import rulePop from '@/pages/home/component/rulePop'
export default {
	components: {
		rulePop
	},
	data() {
		return {
			shopList: [],
			searchForm: {
				order_id: ''
			}
		}
	},
	onShow(e) {
		this.searchForm.order_id = store.state.shopId
		let isLogin = uni.getStorageSync('token')
		if(isLogin) {
			this.getList()
		}
	},
	onHide() {
		store.commit('setShopId', '')
	},
	methods: {
		getList() {
			uni.showLoading({
				title: '加载中'
			})
			quickList(this.searchForm).then((res) => {
				this.shopList = res.data
				uni.hideLoading()
			})
		},
		addCart(item) {
			this.$refs.rulePop.openPop(item)
		},
		goDetail(item) {
			uni.navigateTo({
				url: '/managePackage/pages/shopDetail/index?id=' + item.id
			})
		}
	}
}
</script>

<style scoped lang="scss">
@import './index.scss';
</style>